package cn.star.jots.director.service.impl;

import cn.star.jots.director.mapper.DirectorMapper;
import cn.star.jots.director.pojo.dto.DirectorQuery;
import cn.star.jots.director.pojo.dto.DirectorSaveParam;
import cn.star.jots.director.pojo.entity.Director;
import cn.star.jots.director.pojo.vo.DirectorVO;
import cn.star.jots.director.service.DirectorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;


import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class DirectorServiceImpl implements DirectorService {

    @Autowired
    DirectorMapper directorMapper;

    @Override
    public List<DirectorVO> selectAll(DirectorQuery directorQuery) {
        log.debug("查询导演,参数:{}", directorQuery);
        return directorMapper.selectAll(directorQuery);
    }

    @Override
    public void save(DirectorSaveParam directorSaveParam) {
        log.debug("保存导演,参数:{}", directorSaveParam);
        Director director = new Director();
        BeanUtils.copyProperties(directorSaveParam, director);
        if (directorSaveParam.getId() == null) {
            director.setCreateTime(new Date());
            directorMapper.insert(director);
        } else {
            director.setUpdateTime(new Date());
            directorMapper.update(director);
        }
    }

    @Override
    public void deleteById(@PathVariable Long id) {
        log.debug("删除导演,参数:{}", id);
        directorMapper.deleteById(id);
    }
}
